#include <iostream>
#include <signal.h>
#include <unistd.h>

void PrintOldBlock()
{
    sigset_t _osig, _sig;
    sigemptyset(&_osig); // 可以清空
    sigemptyset(&_sig);  // 可以清空

    std::cout << "block:";
    sigprocmask(SIG_BLOCK, nullptr, &_osig);

    for (int _signum = NSIG; _signum > 0; _signum--)
    {
        if (sigismember(&_osig, _signum))
        {
            std::cout << 1;
        }
        else
        {
            std::cout << 0;
        }
    }
    std::cout << std::endl;
}

void printPending()
{
    sigset_t _pending;
    ::sigpending(&_pending);
    std::cout << "pending:";
    for (int _signum = NSIG; _signum > 0; _signum--)
    {
        if (sigismember(&_pending, _signum))
        {
            std::cout << 1;
        }
        else
        {
            std::cout << 0;
        }
    }
    std::cout << std::endl;
}
void Handle(int _flag)
{

    while (true)
    {

        std::cout << "void Handle (int _flag)" << std::endl;
        PrintOldBlock();
        sleep(1);
        break;
    }
}

int main()
{
    struct sigaction _act, _oact;

    // _act.__sigaction_handler = Handle;
    _act.sa_handler = Handle;

    ::sigaction(2, &_act, &_oact); // 信号捕捉

    while (true)
    {
        std::cout << "main" << std::endl;
        PrintOldBlock();
        pause();
    }
    return 0;

    // 发送信号就是修改用户的pending表
}